﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace btnet.pages
{
    public partial class install : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Bug_Util.do_not_cache(Response);

            string dbname = Request["dbname"];

            if (!string.IsNullOrEmpty(dbname))
            {
                try
                {
                    // don't allow lots of dbs to be created by somebody malicious
                    if (Application["dbs"] == null)
                    {
                        Application["dbs"] = 0;
                    }

                    int dbs = (int)Application["dbs"];

                    if (dbs > 10)
                    {
                        Response.End();
                    }

                    Application["dbs"] = ++dbs;

                    DbUtil.get_sqlconnection();
                    string sql = @"use master
				create database [$db]";

                    sql = sql.Replace("$db", dbname);
                    DbUtil.execute_nonquery(sql);

                    Response.Write("<font color=red><b>Database Created.</b></font>");
                }
                catch (Exception ex)
                {
                    Response.Write("<font color=red><b>" + ex.Message + "</b></font>");
                }
            }
        }
    }
}
